﻿using System;
using System.Runtime.Remoting.Messaging;
using LitJson;

namespace OestsCommon.TcpNet
{
    /// <summary>
    /// 包
    /// </summary>
    public class Packet
    {

        /// <summary>
        /// 传输对象
        /// </summary>
        public object DataObject { get; set; }


        /// <summary>
        /// 字符串形式的数据
        /// </summary>
        public string DataStr
        {
            get
            {
                try
                {
                    if (DataObject == null)
                    {
                        return "";
                    }

                    if (DataObject is Enum || DataObject is int || DataObject is string)
                    {
                        return DataObject.ToString();
                    }
                    else
                    {
                        return JsonMapper.ToJson(DataObject);
                    }
                }
                catch (Exception e)
                {
                    return "序列化数据错误：详细：" + e.Message + "   对象： " + DataObject.ToString();
                }
            }


        }

    }

}